package com.kk.base.entity.home;

import com.kk.base.annotion.ValidateEntity;
import com.kk.base.entity.BaseEntity;
import com.kk.base.entity.common.ExpressMailOrderStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

/**
 * 快递订单
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name="express_mail_order")
@EntityListeners(AuditingEntityListener.class)
@Data
@ToString
public class ExpressMailOrder extends BaseEntity {

    @ManyToOne
    @ValidateEntity(required=true,errorRequiredMsg="用户不能为空!")
    @JoinColumn(name = "home_user_id")
    private HomeUser homeUser;

    @ValidateEntity(required=true,errorRequiredMsg="运单编号不能为空!")
    @Column(name="waybill_number",updatable = false,nullable=false,length=30,unique=true)
    private String waybillNumber;  //运单编号

    @ValidateEntity(required=true, requiredLength =true,minLength=1,maxLength=18,errorRequiredMsg="寄件人姓名不能为空!",errorMinLengthMsg="寄件人姓名长度需大于1!",errorMaxLengthMsg="寄件人姓名长度不能大于18!")
    @Column(name="sender_name",nullable=false,length=20)
    private String senderName;  //寄件人姓名

    @ValidateEntity(required=false, requiredLength =true,maxLength=11,errorMaxLengthMsg="寄件人手机号码长度不能大于11!")
    @Column(name="sender_mobile",length=12)
    private String senderMobile;  //寄件人手机号码

    @ValidateEntity(required=true,errorRequiredMsg="请填写寄件人地址!")
    @Column(name="send_full_address",nullable=false,length=30)
    private String sendFullAddress;    //寄件人省市区

    @ValidateEntity(required=true, requiredLength =true,minLength=1,maxLength=66,errorRequiredMsg="请填写寄件人地址!",errorMinLengthMsg="寄件人地址长度需大于1!",errorMaxLengthMsg="寄件人地址长度不能大于66!")
    @Column(name="send_address",nullable=false,length=70)
    private String sendAddress;   //寄件人详细地址

    @ValidateEntity(required=false, requiredLength =true,maxLength=15,errorMaxLengthMsg="寄件人座机号码长度不能大于15!")
    @Column(name="sender_landline_number",length=18)
    private String senderLandlineNumber;  //寄件人座机号码

    @ValidateEntity(required=true,errorRequiredMsg="寄件人邮箱不能为空!")
    @Column(name="sender_email",nullable=false,length=80)
    private String senderEmail;  //寄件人邮箱

    @ValidateEntity(required=true,errorRequiredMsg="付款方式不能为空!")
    @Enumerated
    @Column(name="payment_method",nullable=false,length=3)
    private PaymentMethodEnum paymentMethod;    //付款方式

    @ValidateEntity(required=true, requiredLength =true,minLength=1,maxLength=18,errorRequiredMsg="收件人姓名不能为空!",errorMinLengthMsg="收件人姓名长度需大于1!",errorMaxLengthMsg="收件人姓名长度不能大于18!")
    @Column(name="recipients_name",nullable=false,length=20)
    private String recipientsName;  //收件人姓名

    @ValidateEntity(required=false, requiredLength = true,maxLength=11,errorMaxLengthMsg = "收件人手机号码长度不能大于11!")
    @Column(name="recipients_mobile",length=12)
    private String recipientsMobile;  //收件人手机号码

    @ValidateEntity(required=true,errorRequiredMsg="请填写收件人地址!")
    @Column(name="recipients_full_address",nullable=false,length=30)
    private String recipientsFullAddress;    //收件人省市区

    @ValidateEntity(required=true, requiredLength =true,minLength=1,maxLength=66,errorRequiredMsg="请填写收件人地址!",errorMinLengthMsg="收件人地址长度需大于1!",errorMaxLengthMsg="收件人地址长度不能大于66!")
    @Column(name="recipients_address",nullable=false,length=70)
    private String recipientsAddress;   //收件人详细地址

    @ValidateEntity(required=false, requiredLength =true,maxLength=15,errorMaxLengthMsg="收件人座机号码长度不能大于15!")
    @Column(name="recipients_landline_number",length=18)
    private String recipientsLandlineNumber;  //收件人座机号码

    @ValidateEntity(required=true,requiredMinValue=true,requiredMaxValue = true,minValue=1,maxValue=10000,errorRequiredMsg="物品重量不能为空!",errorMinValueMsg="物品重量不能小于1KG!",errorMaxValueMsg="物品重量不能大于10000KG!")
    @Column(name="item_weight",nullable=false,length=8)
    private Double itemWeight;  //物品重量

    @ValidateEntity(required=true, requiredLength =true,minLength=1,maxLength=50,errorRequiredMsg="请选择物品类型!",errorMinLengthMsg="请选择物品类型!",errorMaxLengthMsg="物品类型长度不能大于66!")
    @Column(name="item_type",nullable=false,length = 70)
    private String itemType; //物品类型

    @ValidateEntity(required=false)
    @Column(name="remark",length=266)
    private String remark;  //备注

    @Column(name="order_status")
    private Integer orderStatus = ExpressMailOrderStatus.HAVEORDER; //订单状态

    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="pick_up_time")
    private Date pickUpTime;
}
